{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "用户历史记录：\n",
      "david 融通汇成\n",
      "david 人人友信-秒贷\n",
      "david 宁波通商银行-房屋抵押贷\n",
      "andy 永捷金融-优业贷\n",
      "jack 平安银行-公积金贷\n",
      "jack 永捷金融-房产抵押贷\n",
      "jack 融通汇成\n",
      "michale 平安普惠-宅E贷\n",
      "michale 人人友信-秒贷\n",
      "ann 永捷金融-车抵贷 \n",
      "ann 融通汇成\n",
      "ann 阳光财险-阳房贷\n",
      "joel 阳光财险-优房保B\n",
      "joel 光大银行-公积金贷\n",
      "joel 工商银行-经营抵押\n",
      "joel 杭州银行-企业经营贷\n",
      "jim 背包十年:我的职业是旅行\n",
      "jim 阳光财险-优房保B\n",
      "ray 平安普惠-宅E贷\n",
      "ray 光大银行-公积金贷\n",
      "ray 杭州银行-企业经营贷\n",
      "kity 中信银行-房逸贷\n",
      "kity 阳光财险-优房保B\n",
      "kity 平安普惠-宅E贷\n",
      "kity 商银行-经营抵押\n",
      "anna 中信银行-房逸贷\n",
      "anna 永捷金融-房产抵押贷\n",
      "anna 平安普惠-宅E贷\n",
      "anna 光大银行-公积金贷\n",
      "jason 平安普惠-宅E贷\n",
      "jason 商银行-经营抵押\n",
      "jason 中信银行-房逸贷\n",
      "jason 永捷金融-房产抵押贷\n",
      "rk 永捷金融-房产抵押贷\n",
      "bak 融通汇成\n",
      "kavid 平安普惠-宅E贷\n",
      "kavid 光大银行-公积金贷\n",
      "kavid 商银行-经营抵押\n",
      "kavid 融通汇成\n",
      "0 银行 0.03152504935860634\n",
      "1 金融 0.021859709173440933\n",
      "2 抵押 -0.03982890397310257\n",
      "\n",
      "\r",
      " 基于产品名称的 word2vec 协同过滤推荐\n",
      "\n",
      "根据 阳光财险-阳房贷 推荐：\n",
      "\t永捷金融-优业贷 0.08\n",
      "\t商银行-经营抵押 0.07\n",
      "\t光大银行-公积金贷 0.06\n",
      "\t永捷金融-房产抵押贷 0.03\n",
      "\t人人友信-秒贷 0.02\n",
      "\t平安普惠-宅E贷 -0.02\n",
      "\t背包十年:我的职业是旅行 -0.02\n",
      "\t平安银行-公积金贷 -0.03\n",
      "\t中信银行-房逸贷 -0.03\n",
      "\t宁波通商银行-房屋抵押贷 -0.04\n",
      "\n",
      "根据 中信银行-房逸贷 推荐：\n",
      "\t工商银行-经营抵押 0.24\n",
      "\t平安银行-公积金贷 0.12\n",
      "\t阳光财险-优房保B 0.10\n",
      "\t融通汇成 0.09\n",
      "\t平安普惠-宅E贷 0.09\n",
      "\t永捷金融-车抵贷 0.05\n",
      "\t永捷金融-优业贷 -0.00\n",
      "\t背包十年:我的职业是旅行 -0.00\n",
      "\t永捷金融-房产抵押贷 -0.01\n",
      "\t宁波通商银行-房屋抵押贷 -0.02\n",
      "\n",
      "根据 杭州银行-企业经营贷 推荐：\n",
      "\t永捷金融-房产抵押贷 0.27\n",
      "\t光大银行-公积金贷 0.20\n",
      "\t背包十年:我的职业是旅行 0.17\n",
      "\t永捷金融-车抵贷 0.11\n",
      "\t平安银行-公积金贷 0.09\n",
      "\t商银行-经营抵押 0.07\n",
      "\t永捷金融-优业贷 0.05\n",
      "\t阳光财险-优房保B 0.05\n",
      "\t工商银行-经营抵押 0.04\n",
      "\t平安普惠-宅E贷 0.02\n",
      "\n",
      "根据 永捷金融-车抵贷 推荐：\n",
      "\t光大银行-公积金贷 0.17\n",
      "\t工商银行-经营抵押 0.17\n",
      "\t融通汇成 0.11\n",
      "\t杭州银行-企业经营贷 0.11\n",
      "\t商银行-经营抵押 0.06\n",
      "\t平安普惠-宅E贷 0.05\n",
      "\t永捷金融-优业贷 0.05\n",
      "\t中信银行-房逸贷 0.05\n",
      "\t永捷金融-房产抵押贷 0.04\n",
      "\t平安银行-公积金贷 0.02\n",
      "\n",
      "根据 永捷金融-房产抵押贷 推荐：\n",
      "\t杭州银行-企业经营贷 0.27\n",
      "\t阳光财险-优房保B 0.16\n",
      "\t背包十年:我的职业是旅行 0.15\n",
      "\t平安银行-公积金贷 0.12\n",
      "\t光大银行-公积金贷 0.10\n",
      "\t人人友信-秒贷 0.07\n",
      "\t宁波通商银行-房屋抵押贷 0.05\n",
      "\t融通汇成 0.05\n",
      "\t永捷金融-车抵贷 0.04\n",
      "\t阳光财险-阳房贷 0.03\n",
      "\n",
      "根据 平安普惠-宅E贷 推荐：\n",
      "\t商银行-经营抵押 0.15\n",
      "\t宁波通商银行-房屋抵押贷 0.13\n",
      "\t平安银行-公积金贷 0.10\n",
      "\t人人友信-秒贷 0.09\n",
      "\t中信银行-房逸贷 0.09\n",
      "\t阳光财险-优房保B 0.08\n",
      "\t光大银行-公积金贷 0.06\n",
      "\t永捷金融-车抵贷 0.05\n",
      "\t永捷金融-优业贷 0.03\n",
      "\t杭州银行-企业经营贷 0.02\n",
      "\n",
      "根据 阳光财险-优房保B 推荐：\n",
      "\t永捷金融-房产抵押贷 0.16\n",
      "\t融通汇成 0.13\n",
      "\t平安银行-公积金贷 0.11\n",
      "\t中信银行-房逸贷 0.10\n",
      "\t平安普惠-宅E贷 0.08\n",
      "\t永捷金融-优业贷 0.08\n",
      "\t背包十年:我的职业是旅行 0.05\n",
      "\t商银行-经营抵押 0.05\n",
      "\t杭州银行-企业经营贷 0.05\n",
      "\t人人友信-秒贷 0.04\n",
      "\n",
      "根据 商银行-经营抵押 推荐：\n",
      "\t平安普惠-宅E贷 0.15\n",
      "\t光大银行-公积金贷 0.10\n",
      "\t阳光财险-阳房贷 0.07\n",
      "\t杭州银行-企业经营贷 0.07\n",
      "\t宁波通商银行-房屋抵押贷 0.06\n",
      "\t永捷金融-车抵贷 0.06\n",
      "\t阳光财险-优房保B 0.05\n",
      "\t人人友信-秒贷 -0.03\n",
      "\t背包十年:我的职业是旅行 -0.05\n",
      "\t永捷金融-优业贷 -0.07\n",
      "\n",
      "根据 永捷金融-优业贷 推荐：\n",
      "\t平安银行-公积金贷 0.20\n",
      "\t阳光财险-优房保B 0.08\n",
      "\t阳光财险-阳房贷 0.08\n",
      "\t光大银行-公积金贷 0.06\n",
      "\t杭州银行-企业经营贷 0.05\n",
      "\t永捷金融-车抵贷 0.05\n",
      "\t平安普惠-宅E贷 0.03\n",
      "\t中信银行-房逸贷 -0.00\n",
      "\t融通汇成 -0.01\n",
      "\t永捷金融-房产抵押贷 -0.01\n",
      "\n",
      "根据 宁波通商银行-房屋抵押贷 推荐：\n",
      "\t人人友信-秒贷 0.23\n",
      "\t平安普惠-宅E贷 0.13\n",
      "\t工商银行-经营抵押 0.12\n",
      "\t背包十年:我的职业是旅行 0.09\n",
      "\t商银行-经营抵押 0.06\n",
      "\t永捷金融-房产抵押贷 0.05\n",
      "\t杭州银行-企业经营贷 -0.00\n",
      "\t光大银行-公积金贷 -0.01\n",
      "\t中信银行-房逸贷 -0.02\n",
      "\t永捷金融-车抵贷 -0.03\n",
      "\n",
      "根据 光大银行-公积金贷 推荐：\n",
      "\t杭州银行-企业经营贷 0.20\n",
      "\t永捷金融-车抵贷 0.17\n",
      "\t永捷金融-房产抵押贷 0.10\n",
      "\t商银行-经营抵押 0.10\n",
      "\t融通汇成 0.08\n",
      "\t平安普惠-宅E贷 0.06\n",
      "\t永捷金融-优业贷 0.06\n",
      "\t阳光财险-阳房贷 0.06\n",
      "\t阳光财险-优房保B 0.01\n",
      "\t宁波通商银行-房屋抵押贷 -0.01\n",
      "\n",
      "根据 工商银行-经营抵押 推荐：\n",
      "\t中信银行-房逸贷 0.24\n",
      "\t永捷金融-车抵贷 0.17\n",
      "\t宁波通商银行-房屋抵押贷 0.12\n",
      "\t背包十年:我的职业是旅行 0.05\n",
      "\t融通汇成 0.05\n",
      "\t杭州银行-企业经营贷 0.04\n",
      "\t永捷金融-房产抵押贷 0.03\n",
      "\t阳光财险-优房保B 0.02\n",
      "\t平安银行-公积金贷 -0.00\n",
      "\t人人友信-秒贷 -0.01\n",
      "\n",
      "根据 融通汇成 推荐：\n",
      "\t阳光财险-优房保B 0.13\n",
      "\t永捷金融-车抵贷 0.11\n",
      "\t中信银行-房逸贷 0.09\n",
      "\t光大银行-公积金贷 0.08\n",
      "\t永捷金融-房产抵押贷 0.05\n",
      "\t工商银行-经营抵押 0.05\n",
      "\t杭州银行-企业经营贷 -0.00\n",
      "\t永捷金融-优业贷 -0.01\n",
      "\t平安普惠-宅E贷 -0.03\n",
      "\t人人友信-秒贷 -0.04\n",
      "\n",
      "根据 人人友信-秒贷 推荐：\n",
      "\t宁波通商银行-房屋抵押贷 0.23\n",
      "\t背包十年:我的职业是旅行 0.13\n",
      "\t平安普惠-宅E贷 0.09\n",
      "\t永捷金融-房产抵押贷 0.07\n",
      "\t阳光财险-优房保B 0.04\n",
      "\t阳光财险-阳房贷 0.02\n",
      "\t杭州银行-企业经营贷 0.01\n",
      "\t平安银行-公积金贷 -0.00\n",
      "\t工商银行-经营抵押 -0.01\n",
      "\t永捷金融-车抵贷 -0.01\n",
      "\n",
      "根据 背包十年:我的职业是旅行 推荐：\n",
      "\t杭州银行-企业经营贷 0.17\n",
      "\t永捷金融-房产抵押贷 0.15\n",
      "\t人人友信-秒贷 0.13\n",
      "\t宁波通商银行-房屋抵押贷 0.09\n",
      "\t阳光财险-优房保B 0.05\n",
      "\t工商银行-经营抵押 0.05\n",
      "\t中信银行-房逸贷 -0.00\n",
      "\t永捷金融-优业贷 -0.02\n",
      "\t阳光财险-阳房贷 -0.02\n",
      "\t平安银行-公积金贷 -0.04\n",
      "\n",
      "根据 平安银行-公积金贷 推荐：\n",
      "\t永捷金融-优业贷 0.20\n",
      "\t永捷金融-房产抵押贷 0.12\n",
      "\t中信银行-房逸贷 0.12\n",
      "\t阳光财险-优房保B 0.11\n",
      "\t平安普惠-宅E贷 0.10\n",
      "\t杭州银行-企业经营贷 0.09\n",
      "\t永捷金融-车抵贷 0.02\n",
      "\t人人友信-秒贷 -0.00\n",
      "\t工商银行-经营抵押 -0.00\n",
      "\t光大银行-公积金贷 -0.01\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:65: DeprecationWarning: Call to deprecated `most_similar` (Method will be removed in 4.0.0, use self.wv.most_similar() instead).\n"
     ]
    }
   ],
   "source": [
    "from gensim.models import Word2Vec\n",
    "import gensim\n",
    "\n",
    "\n",
    "model_file = 'rong360_user_history.model'\n",
    "\n",
    "with open('rong360_user_history.txt') as f:\n",
    "    prefs_str = ''.join(f.readlines())\n",
    "print(\"用户历史记录：\")\n",
    "print(prefs_str)\n",
    "def read_prefs(prefs_str):\n",
    "    prefs = {}\n",
    "    for line in prefs_str.split('\\n'):\n",
    "        parts = line.rstrip().split()\n",
    "        if len(parts) == 2:\n",
    "            userId, itemId = parts\n",
    "            prefs.setdefault(userId, {})\n",
    "            prefs[userId].update({itemId:1})\n",
    "    return prefs\n",
    "\n",
    "prefs = read_prefs(prefs_str)\n",
    "\n",
    "# print(\"prefs...\")\n",
    "# print(prefs)\n",
    "\n",
    "def sents_from_prefs(prefs):\n",
    "    sents = []\n",
    "    for v in prefs.values():\n",
    "        sent = ''\n",
    "        for b in v.keys():\n",
    "            sent += ' ' + b.replace(' ', '')\n",
    "        sents.append(sent)\n",
    "    return sents\n",
    "\n",
    "def flatMap(vocab):\n",
    "    ret = []\n",
    "    for i in vocab:\n",
    "        if type(i) == type('a'):\n",
    "            ret.append(i)\n",
    "        elif type(i) == type([]):\n",
    "            for j in i:\n",
    "                ret.append(j)\n",
    "    return ret\n",
    "\n",
    "def calc_item_cf():\n",
    "    sents = sents_from_prefs(prefs)\n",
    "#     print(\"sents.....\")\n",
    "#     print(sents)\n",
    "    vocab = [s.split() for s in sents]\n",
    "#     print(\"vocab.....\")\n",
    "#     print(vocab)\n",
    "    model = Word2Vec(vocab, size=100, window=5, min_count=1, workers=4,sg=1)\n",
    "    model.wv.save_word2vec_format(model_file, binary=False)\n",
    "#     print(\"positive....\")\n",
    "    \n",
    "    \n",
    "    for i, item in enumerate(items):\n",
    "        print(i, item[0], item[1])\n",
    "#     model = Word2Vec.load(model_file)\n",
    "#     print(\"flatMap........\")\n",
    "#     print(flatMap(vocab))\n",
    "    print('\\n\\r 基于产品名称的 word2vec 协同过滤推荐')\n",
    "    for item in set(flatMap(vocab)):\n",
    "        print('\\n根据 %s 推荐：' % item)\n",
    "        for item_score in model.most_similar(positive=[item]):\n",
    "            item, score = item_score\n",
    "            print('\\t%s %.2f' % (item, score))\n",
    "\n",
    "calc_item_cf()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:8: DeprecationWarning: Call to deprecated `__getitem__` (Method will be removed in 4.0.0, use self.wv.__getitem__() instead).\n",
      "  \n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAD8CAYAAACfF6SlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4xLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvDW2N/gAAFWVJREFUeJzt3X+MVeWdx/H3h5mwohVHyxT54RSaRVLSbqS9ITTG1q24jP0DSNq1uDVgYku2xmaTtqQQN2bW/qMlVbqpmy2xG61Nd7SGIhtpRkGNSeu4DMFqwIxQ2uoMqGgds6ZjZeS7f9wDuY53uOOcc+8d5vm8EjLnPOfLeb5chs8cnnvuvYoIzMwsLdOa3YCZmTWew9/MLEEOfzOzBDn8zcwS5PA3M0uQw9/MLEEOfzOzBDn8zcwS5PA3M0tQa7MbGMusWbNiwYIFzW7DzOyssm/fvtcjor1WXSHhL6kT+BHQAtwTEbePOt4B3Ae0ZTWbImLXmc65YMEC+vr6imjPzCwZkv40nrrcyz6SWoC7gWuAJcB1kpaMKvtX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qyKiGR/UPZ7HdwB4JiJOAH+Q9CLlHwZ7G9Pi+4yn3xuBToCIeFrSOZTf82fM5aoUln12Auuz7fXAw1Vq9gJtkk6tQ38RONiA3qqp2W9EfC0iOiJiAeWln5/VK/jHoWa/kqYDv6Lc50MN7O2UvcAiSQuzXtZS7rtS5Z/jK8DjkT171gQ1+5W0FPgJsKrJ69FQo9+IeCsiZkXEgux7tpdy380Ifhjf98MOylf9SJpFeRnoSCObrDCefl8CrgKQ9EngHOD4Gc/arGewG/WL8rrtHuAQsBu4KBsvAfdU1F0NPAc8D9wLTJ/M/VbU30Bz7/ap2S9wPXACeLbi12UN7vNLwIuUn2u4JRu7jXIIkf1j+SVwGPhf4BPNekzH2e9u4NWKx3PnZO53VO2TNPFun3E+vqK8VHUwy4S1k7zfJcBvKN8J9CzwD7XO6Vf4mpklKIVlHzMzG8Xhb2aWIIe/mVmCHP5mZgly+JuZJcjhb2aWIIe/mVmCHP5mZgn6f/7NyV6wbPa9AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.decomposition import PCA\n",
    "from matplotlib import pyplot\n",
    "%matplotlib inline\n",
    "# 利用语料训练模型\n",
    "# model = Word2Vec(sentences,window=5, min_count=1)\n",
    "\n",
    "# 基于2d PCA拟合数据\n",
    "X = model[model.wv.vocab]\n",
    "pca = PCA(n_components=2)\n",
    "result = pca.fit_transform(X)\n",
    "# 可视化展示\n",
    "pyplot.scatter(result[:, 0], result[:, 1])\n",
    "words = list(model.wv.vocab)\n",
    "for i, word in enumerate(words):\n",
    "\tpyplot.annotate(word, xy=(result[i, 0], result[i, 1]))\n",
    "pyplot.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
